import datetime
from flask import Blueprint,request,jsonify

from views.db import Db

import json

from utils.jwtc import JWTE, myjwt

from utils.Make_password import make_password

from utils.myfile import MyFile

from utils.redis import rs

from utils.acl import ACL

import redis

import re

from views.db import Db

import time

bp_user = Blueprint("user",__name__)



@bp_user.route('/loginM',methods = ['POST','GET'])
def loginM():
    if request.method == 'POST':
        data = request.data
        if data:
            data = json.loads(data)
        else:
            data = request.form
   
        sql = """select * from user where usernum = '%s'"""%(data['username'])
        res = Db.get_one(sql)
        if res:
            if res['password'] == data['password']:
                userid = res['id']
                token = myjwt.jwt_en({'data':{'userid':res['id']}})
                ress = ACL.get_vue(userid)
                # 把url存入redis,
                r.insert_set('users'+str(userid),ress)
                aa = r.find_set('users'+str(userid))
                print(aa)
                return jsonify({'code':200,"mes":"登陆成功","token":token,'userid':userid,"url":aa})
            else:
                return jsonify({'code': 20021, "mes": "密码错误"})
        else:
            return jsonify({'code': 20021,"mes":"账户不存在"})
      

  



        
                   
                   
                    
            
